# The American Viewer: Political Consequences of Entertainment Media
# Eunji Kim and Shawn Patterson Jr 
# American Political Science Review 
# Replication File [Table 3]



table3 <- read.csv("table3_censored.csv")


## Table 3. No Effects of Another NBC 9pm Program 

# Column 1: Primary vote share, OLS 
ols_pri_wg <- felm(trumpshare_primary~  RTG_9pm_July + romneyshare12_new + 
                     log(population_04 +1) +
                     log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                     collegeP_04 + foreignBP_04 + unemR_04   + samesex_census  + religion_allP +
                     log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x   | 
                     STATE  | 0 | 0 , 
                   data = table3, weights=table3$sum_CNTYTVHH) 

stargazer(ols_pri_wg, no.space=TRUE,type="text" )

# Column 2: Primary vote share, 2SLS  

iv_pri_wg <- felm(trumpshare_primary~  romneyshare12_new + 
                    log(population_04 +1) +
                    log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                    collegeP_04 + foreignBP_04 + unemR_04    +  samesex_census  + religion_allP +
                    log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x  | 
                    STATE  | (RTG_9pm_July  ~ RTG_8PM_July)| 0 , 
                  data = table3, weights=table3$sum_CNTYTVHH) 

stargazer(iv_pri_wg, no.space=TRUE,type="text" )


# Column 3: General vote share, OLS 
 
ols_prez_wg <- felm(trumpshare16_new ~  RTG_9pm_July + romneyshare12_new + 
                      log(population_04 +1) +
                      log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                      collegeP_04 + foreignBP_04 + unemR_04   + samesex_census  + religion_allP +
                      log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x   | 
                      STATE  | 0 | 0 ,  data = table3, weights=table3$sum_CNTYTVHH) 

# Column 4: General vote share, 2SLS  

iv_prez_wg <- felm(trumpshare16_new~  romneyshare12_new + 
                     log(population_04 +1) +
                     log(medianHHI_04+1) + femaleP_04 + age65P_04 + whiteP_04 + blackP_04  +
                     collegeP_04 + foreignBP_04 + unemR_04    +  samesex_census  + religion_allP +
                     log(avg_outflow_movers + 1) + log(avg_inflow_movers + 1 ) + pop_density.x  | 
                     STATE  | (RTG_9pm_July  ~ RTG_8PM_July)| 0 , 
                   data = table3, weights=table3$sum_CNTYTVHH) 



# F statistics 

iv_pri_wg$stage1$iv1fstat$RTG_9pm_July["F"]
iv_prez_wg$stage1$iv1fstat$RTG_9pm_July["F"]

stargazer(ols_pri_wg, iv_pri_wg, ols_prez_wg, iv_prez_wg,   
                                   star.cutoffs = c(.05,.01,.001),
                                   title="Placebo Test - Table 3 Full Results",
                                   dep.var.caption = "",
                                   label = "tab2",
                                   dep.var.labels=c('Primary - OLS',  'Primary -IV', 
                                                    'General - OLS', 'General - IV'),
                                   omit.stat=c("adj.rsq","LL","ser","f"),
                                   keep.stat = c("n"),
                                   no.space=TRUE,
                                   omit = c('STATE'),
                                   star.char = c("*", "**", "***"), 
                                   notes = c("* p<0.05; ** p<0.01; *** p<0.001"), 
                                   notes.append = F,
                                   notes.align="l",
                                   digits=3,
                                   align = TRUE, type="text")

